import request from '@/utils/request'

// 查询设备列表
export function listDevice(query) {
  return request({
    url: '/device/device/list',
    method: 'get',
    params: query
  })
}

// 查询设备列表
export function managerList(query) {
  return request({
    url: '/device/device/managerList',
    method: 'get',
    params: query
  })
}

// 查询设备详细
export function getDevice(id) {
  return request({
    url: '/device/device/' + id,
    method: 'get'
  })
}

// 新增设备
export function addDevice(data) {
  return request({
    url: '/device/device',
    method: 'post',
    data: data
  })
}

// 修改设备
export function updateDevice(data) {
  return request({
    url: '/device/device',
    method: 'put',
    data: data
  })
}

// 删除设备
export function delDevice(id) {
  return request({
    url: '/device/device/' + id,
    method: 'delete'
  })
}

// 获取传感器定义
export function seriesIoOptions(query) {
  return request({
    url: `/device/seriesIo/seriesIoOptions`,
    method: 'get',
    params:query
  })
}

// 配置串口标识
export function autoConfigurationSerialIO(id) {
  return request({
    url: '/device/device/autoConfigurationSerialIO',
    method: 'get'
  })
}

// 配置串口标识
export function updateSerialIo() {
  return request({
    url: '/device/device/updateSerialIo/',
    method: 'get'
  })
}

// 配置串口标识
export function getDeviceInfo(id) {
  return request({
    url: '/device/device/getDeviceInfo/'+id,
    method: 'get'
  })
}

// 更新传感器数据
export function updateSensor(data) {
  return request({
    url: '/device/sensor/update',
    method: 'put',
    data:data
  })
}

// 删除传感器
export function delSensor(id) {
  return request({
    url: `/device/sensor/${id}`,
    method: 'delete'
  })
}


// 配置串口标识
export function getDeviceData(id) {
  return request({
    url: '/device/device/getDeviceData/'+id,
    method: 'get'
  })
}

// 同步时间
export function syncDeviceTime(id) {
  return request({
    url: '/device/device/syncDeviceTime/'+id,
    method: 'get'
  })
}


// 传感器控制
export function deviceCommand(data) {
  return request({
    url: '/device/device/command',
    method: 'post',
    data:data
  })
}

// 当前固件
export function firmwareUpgrade() {
  return request({
    url: '/firmware/firmwareUpgrade/current',
    method: 'get',
    params:{}
  })
}

// 升级固件
export function upgrade(data) {
  return request({
    url: '/device/device/upgrade',
    method: 'post',
    data:data
  })
}

// 绑定传感器
export function bindControlSensor(data) {
  return request({
    url: '/device/device/bindControlSensor',
    method: 'post',
    data:data
  })
}

// 传感器chart
export function trendData(data) {
  return request({
    url: '/data/sensorData/trendData',
    method: 'get',
    params:data
  })
}

// 查询设备报警数据列表
export function listEventData(query) {
  return request({
    url: '/data/eventData/list',
    method: 'get',
    params: query
  })
}

// 传感器日志
export function listCmdData(query) {
  return request({
    url: '/data/cmdData/list',
    method: 'get',
    params: query
  })
}

//新增设备控制组合
export function createMergeControl(data) {
  return request({
    url: '/device/mergeControl/add',
    method: 'post',
    data: data
  })
}

//编辑设备控制组合
export function updateMergeControl(data) {
  return request({
    url: '/device/mergeControl/update',
    method: 'put',
    data: data
  })
}

//删除设备控制组合
export function delMergeControl(id) {
  return request({
    url: `/device/mergeControl/${id}`,
    method: 'delete'
  })
}

//设备控制组合命令
export function multipleCommand(data) {
  return request({
    url: `/device/device/multipleCommand`,
    method: 'post',
    data:data
  })
}

//设备控制组合命令
export function copyConfig(data) {
  return request({
    url: `/device/device/copyConfig`,
    method: 'put',
    data:data
  })
}

//清除传感器数据
export function clearData(id) {
  return request({
    url: `/device/sensor/clearData/${id}`,
    method: 'get',
  })
}

//设备状态列表
export function deviceStatuList(params) {
  return request({
    url: `/device/deviceStatus/list`,
    method: 'get',
    params:params
  })
}

//切换企业
export function changeCompany(data) {
    return request({
      url: `/device/device/changeCompany`,
      method: 'put',
      data:data
    })
  }


//刷新设备缓存
export function refreshCache(params) {
  return request({
    url: `/device/device/refreshCache/${params.id}`,
    method: 'get'
  })
}

//配置任务
export function taskConfig(params) {
  return request({
    url: `/device/device/taskConfig/${params.id}`,
    method: 'get'
  })
}

export function deleteDeviceSensor(deviceId,control){
  return request({
    url: `/device/sensor/deleteDeviceSensorByDeviceId/${deviceId}/${control}`,
    method: 'delete'
  })
}

export function deleteTaskConfig(deviceId,sensorId){
  return request({
    url: `/device/device/deleteTaskConfig/${deviceId}&sensorId=${sensorId}}`,
    method: 'delete'
  })
}

// 查询设备列表
export function listEsDevice(query) {
  return request({
    url: '/esDevice/deviceList',
    method: 'get',
    params: query
  })
}

// 查询设备列表
export function esTrendData(query) {
  return request({
    url: '/esDevice/trendData',
    method: 'get',
    params: query
  })
}
